﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using KeRui.Common;

public partial class Manage_User_Password : System.Web.UI.Page
{
    private KeRui.BLL.Account bllAccount;
    protected KeRui.Model.Account modelAccount;
    public string Act = ManageHelper.PageAct();
    int loginUserID = -1;
    private ManageErrMsg nsb = new ManageErrMsg();
    protected void Page_Load(object sender, EventArgs e)
    {
        ManageHelper.CheckAdminLogin();//是否登录判断
        bllAccount = new KeRui.BLL.Account();
        loginUserID = KeRui.BLL.Account.GetLoginUserID();
        modelAccount = bllAccount.GetModel(loginUserID);
        if (modelAccount == null)
        {
            Response.Write("不存在该管理员。");
        }
        if (Act.ToLower() == "editsave")
        {
            AccountEditSave();
        }
    }

    private void AccountEditSave()
    {
        KeRui.Model.Account NewModelAccount = new KeRui.Model.Account();
        string oldPwd = Utils.MD5(PageRequest.GetString("oldPwd"));
        if (oldPwd == "")
        {
            nsb.AddErr("请输入旧密码");
        }
        string newPwd = Utils.MD5(PageRequest.GetString("newPwd"));
        if (newPwd == "")
        {
            nsb.AddErr("请输入新密码。");
        }
        string chkNewPwd = Utils.MD5(PageRequest.GetString("chkNewPwd"));
        if (chkNewPwd == "")
        {
            nsb.AddErr("请输入确认密码。");
        }
        if (newPwd != chkNewPwd)
        {
            nsb.AddErr("新密码和确认密码不相同。");
        }
        NewModelAccount.Password = newPwd;
        NewModelAccount.UserID = loginUserID;
        nsb.ChkErr();
        int retInt = bllAccount.Update(NewModelAccount, oldPwd);
        if (retInt == -1)
        {
            nsb.AddErr("旧密码有误。");
            nsb.ChkErr();
        }
        else
        {
            Response.Redirect("Password.aspx?sucmsg=恭喜！密码修改成功");
        }
    }
}
